package com.piece.blog.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.piece.admin.api.dto.SysUserDTO;
import com.piece.core.elasticsearch.annotations.Document;
import com.piece.core.elasticsearch.annotations.Field;
import com.piece.core.framework.support.model.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

@Data
@Entity
@NoArgsConstructor
@Table(name = "blog_article")
@ApiModel(value = "文章表:blog_article")
@Document(indexName = "blog_article")
public class Article extends BaseEntity implements Serializable {

    @Id
    @Field
    @Column(name = "article_id", length = 11)
    @ApiModelProperty(value = "主键")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long articleId;

    @Column(name = "channel")
    @ApiModelProperty(value = "栏目")
    private String channel;

    @Column(name = "title")
    @ApiModelProperty(value = "标题")
    @Field(searchAnalyzer = true)
    private String title;

    @Column(name = "summary")
    @ApiModelProperty(value = "摘要")
    @Field(searchAnalyzer = true)
    private String summary;

    @Column(name = "editor")
    @ApiModelProperty(value = "编辑器", notes = "tinymce(默认),markdown")
    private String editor;

    @Column(name = "thumbnail")
    @ApiModelProperty(value = "预览图")
    private String thumbnail;

    @Column(name = "tags")
    @ApiModelProperty(value = "标签")
    private String tags;

    @Transient
    private List<String> tagsArr;

    @Column(name = "open")
    @ApiModelProperty(value = "阅读权限", notes = "0=公开, 1=私密")
    private String open;

    @Column(name = "member_growth")
    @ApiModelProperty(value = "所需会员成长值", notes = "对应会员等级表growth_point字段")
    private Long memberGrowth;

    @Column(name = "crypto")
    @ApiModelProperty(value = "加密标志", notes = "0=加密, 1=不加密")
    private String crypto;

    @Column(name = "salt")
    @JSONField(serialize = false)
    @JsonIgnore
    @ApiModelProperty(value = "分享码")
    private String salt;

    @Column(name = "favors")
    @ApiModelProperty(value = "收藏数")
    private Integer favors;

    @Column(name = "comments")
    @ApiModelProperty(value = "评论数")
    private Integer comments;

    @Column(name = "views")
    @ApiModelProperty(value = "阅读数")
    private Integer views;

    @Column(name = "featured")
    @ApiModelProperty(value = "推荐状态", notes = "0=推荐, 1=未推荐")
    private String featured;

    @Field
    @Column(name = "weight")
    @ApiModelProperty(value = "排序值")
    private Integer weight;

    @Column(name = "source")
    @ApiModelProperty(value = "文章来源")
    private String source;

    @Column(name = "attach")
    @ApiModelProperty(value = "文章附件")
    private String attach;

    @Transient
    @Field(searchAnalyzer = true)
    @ApiModelProperty(value = "文章内容")
    private String content;

    @Transient
    @Field(searchAnalyzer = true)
    @ApiModelProperty(value = "文章html内容")
    private String html;

    @Column(name = "group_name")
    @ApiModelProperty(value = "文章分组")
    private String group;

    @Column(name = "group_index")
    @ApiModelProperty(value = "文章分组排序")
    private Integer groupIndex;

    @Column(name = "direction")
    @ApiModelProperty(value = "显示方向", notes = "横向:horizontal,纵向:vertical")
    private String direction;

    @Column(name = "status")
    @ApiModelProperty(value = "状态", notes = "0=发布, 1=删除, 2=草稿")
    private String status;

    @Transient
    @ApiModelProperty(value = "作者信息")
    private SysUserDTO user;

    @Transient
    @ApiModelProperty(value = "发布文章数量")
    private int userPosts;

    @Transient
    @ApiModelProperty(value = "人气数量")
    private int userFavors;

    @Transient
    @ApiModelProperty(value = "关注数量")
    private int userWatchers;

    @Transient
    @ApiModelProperty(value = "是否已收藏")
    private Boolean hasFavored;

    @Transient
    @ApiModelProperty(value = "是否已关注")
    private Boolean hasWatched;

    @Transient
    @ApiModelProperty(value = "当前系列文章列表")
    private List<Article> groups;

    @Transient
    @ApiModelProperty(value = "当前系列文章位置")
    private int current;

    @Transient
    @ApiModelProperty(value = "评论列表")
    private List<ArticleComment> commentList;
}
